﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace LightWadf.Result
{
    public class FileResult
    {
        public string FileName
        {
            get;
            set;
        }

        public FileResult(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new TypeInitializationException("LightWadf.Result.HtmlResult", new Exception("HtmlResult 的初始化参数为空"));
            }
            else
            {
                string[] paths = filePath.Split('/', '\\');
                string fileName = AppDomain.CurrentDomain.BaseDirectory;
                foreach (string path in paths)
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        fileName = Path.Combine(fileName, path);
                    }
                }
                if (File.Exists(fileName))
                {
                    this.FileName = fileName;
                }
                else
                {
                    throw new TypeInitializationException("LightWadf.Result.HtmlResult", new Exception("文件不存在 HtmlResult 初始化失败"));
                }
            }
        }
    }
}